//
//  YTViewController.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/4/27.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTViewController.h"
#import <YYWebImage/YYWebImage.h>

@interface YTViewController ()
@property (weak, nonatomic) IBOutlet UIButton *refreshButton;
@end

@implementation YTViewController

+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    YTViewController *viewController = [super allocWithZone:zone];
    @weakify(viewController);
    [[viewController rac_signalForSelector:@selector(viewDidLoad)] subscribeNext:^(id x) {
        @strongify(viewController);
        [viewController initialize];
        [viewController bindViewModel];
    }];
    return viewController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
    @weakify(self);
    [[self rac_signalForSelector:@selector(viewWillAppear:)] subscribeNext:^(id x) {
        @strongify(self);
        if (self.naviType == YTNavigationBarBlueStyle) {
            [self yt_changStatusBarWithStyle:UIStatusBarStyleLightContent];
        } else {
            [self yt_changStatusBarWithStyle:UIStatusBarStyleDefault];
        }
    }];
}

- (void)setNaviType:(YTNavigationBarStyle)naviType {
    _naviType = naviType;
    switch (self.naviType) {
        case YTNavigationBarBlueStyle: {
            [self.navigationController.navigationBar setBackgroundImage:[UIImage yy_imageWithColor:kMainBlueColor] forBarMetrics:0];
            [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
            self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        }
            break;
        case  YTNavigationBarClearStyle: {
            [self.navigationController.navigationBar setBackgroundImage:[UIImage yy_imageWithColor:[UIColor clearColor]] forBarMetrics:0];
            [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
            self.navigationController.navigationBar.tintColor = [UIColor clearColor];
        }
            break;
        case YTNavigationBarDefaultStyle:
            self.navigationController.navigationBar.tintColor = [UIColor blackColor];
            break;
        default: 
            self.navigationController.navigationBar.tintColor = [UIColor blackColor];
            break;
    }
}

- (void)bindViewModel {}

- (void)initialize {};

- (void)loseConnectionRefreshAction:(void (^)())refreshAction {
    
    UIView *coverView = [[NSBundle mainBundle] loadNibNamed:@"YTViewController" owner:self options:nil].firstObject;
    coverView.frame = self.view.bounds;
    [self.view addSubview:coverView];
    
    [self.refreshButton bk_whenTapped:^{
        [coverView removeFromSuperview];
        
        if (refreshAction) {
            refreshAction();
        }
    }];
}

- (void)dealloc {
    NSLog(@"%@ was dealloc", NSStringFromClass(self.class));
}

@end
